package com.wd.buycar.view.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.LayoutManager
import com.blankj.utilcode.util.ToastUtils
import com.wd.buycar.R
import com.wd.buycar.databinding.ActivityContrastBinding
import com.wd.buycar.view.adapter.ContrastAdapter
import com.wd.common.DataHelper
import com.wd.common.base.BaseActivity
import com.wd.common.bean.ContrastBean
import com.wd.common.bean.QuickSearchBean
import com.wd.common.viewmodel.MyViewModel

class ContrastActivity : BaseActivity<ActivityContrastBinding, Any>() {
    override fun getViewBinding() =  ActivityContrastBinding.inflate(layoutInflater)
    val viewModel: MyViewModel by viewModels()
    private  var list = ArrayList<ContrastBean.Result>()
    private lateinit var mAdapter : ContrastAdapter
    override fun initData() {
        mAdapter = ContrastAdapter(this,list)
        binding.recContrast.apply {
            layoutManager = LinearLayoutManager(this@ContrastActivity,RecyclerView.HORIZONTAL,false)
            adapter = mAdapter
        }
        var toString = DataHelper.list.toString()
        toString = toString.substring(1, toString.length - 1)
        toString = toString.replace(" ","")
        viewModel.findCarParameter(toString)
        viewModel.findCarParameter.observe(this){
            it?.let {
                list.addAll(it.result)
                ToastUtils.showShort(list.size)
                mAdapter.notifyDataSetChanged()
            }
        }
    }

}